package view

import "math"

type Constant_Integer struct {
	Tag   uint8
	U4    []uint8
	Value uint32
}

func (self *Constant_Integer) ReadConstant(cr *ClassReader) {
	self.U4 = cr.readUInt8s(2)
}

func (self *Constant_Integer) ReadValue(cr ClassReader, cp ConstantPoolInfo) {
	self.Value = cr.readUInt32(self.U4)
}

type Constant_Float struct {
	Tag   uint8
	U4    []uint8
	Value float32
}

func (self *Constant_Float) ReadConstant(cr *ClassReader) {
	self.U4 = cr.readUInt8s(4)
}

func (self *Constant_Float) ReadValue(cr ClassReader, cp ConstantPoolInfo) {
	self.Value = math.Float32frombits(cr.readUInt32(self.U4))
}

type Constant_Double struct {
	Tag   uint8
	U8    []uint8
	Value float64
}

func (self *Constant_Double) ReadConstant(cr *ClassReader) {
	self.U8 = cr.readUInt8s(8)
}

func (self *Constant_Double) ReadValue(cr ClassReader, cp ConstantPoolInfo) {
	self.Value = math.Float64frombits(cr.readUInt64(self.U8))
}

type Constant_Long struct {
	Tag   uint8
	U8    []uint8
	Value uint64
}

func (self *Constant_Long) ReadConstant(cr *ClassReader) {
	self.U8 = cr.readUInt8s(8)
}
func (self *Constant_Long) ReadValue(cr ClassReader, cp ConstantPoolInfo) {
	self.Value = cr.readUInt64(self.U8)
}

type Constant_Utf8 struct {
	Tag uint8
	Len uint16
	Str string
}

func (self *Constant_Utf8) ReadConstant(cr *ClassReader) {
	self.Len = cr.readUInt16(cr.readUInt8s(2))
	self.Str = cr.readUtf8(self.Len)
}

func (self *Constant_Utf8) ReadValue(cr ClassReader, cp ConstantPoolInfo) {

}

type Constant_String struct {
	Tag         uint8
	StringIndex uint16
	Str         Constant
}

func (self *Constant_String) ReadConstant(cr *ClassReader) {
	self.StringIndex = cr.readUInt16(cr.readUInt8s(2))
}

func (self *Constant_String) ReadValue(cr ClassReader, cp ConstantPoolInfo) {
	self.Str = cp.ConstantList[int(self.StringIndex)-1]
}
